<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="chrome=1" />
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
  </head>
  <body>
    <script type="text/javascript">
      //通用
      if (document.addEventListener) {
        document.addEventListener(
          "visibilitychange",
          function() {
            console.log("进来了");
            console.log(document.visibilityState);
          },
          false
        );
      }

      //IE
      // if (document.addEventListener) {
      //   document.addEventListener("msvisibilitychange", function() {
      //     console.log(document.msVisibilityState);
      //     console.log(3333333333);
      //   });
      // }

      // if (document.addEventListener) {
      //   document.addEventListener("webkitvisibilitychange", function() {
      //     console.log(document.webkitVisibilityState);
      //   });
      // }

      $(window).resize(function() {
        //当浏览器大小变化时
        console.log($(window).width()); //浏览器高度
        console.log($(window).height()); //浏览器宽度
      });

      setInterval(function() {
        console.log(document.hidden, " document.hidden");
        console.log(document.mozHidden, " document.mozHidden ");
        console.log(document.msHidden, " document.msHidden ");
        console.log(document.webkitHidden, " document.webkitHidden ");
      }, 3000);
    </script>
  </body>
</html>
